#include "WeiQiClient.h"
GO_PLAYER_STATE_T* CWeiQiClient::GetPlayerState(unsigned int player_id)
{
		if(player_id==0) return NULL;
		int sz=m_vectorPlayerStates.size();
		for(int i=0;i<sz;i++)
		{
			GO_PLAYER_STATE_T* pPlayer = m_vectorPlayerStates[i];
			if(player_id==pPlayer->palyer_id)
			{
				return pPlayer;
			}

		}
		return NULL;
}

	GO_INSTANCE_STATE_T* CWeiQiClient::GetGoInstance(unsigned int instance_id)
	{
		if(instance_id==0) return NULL;

		for(int i=0;i<m_vectorInstances.size();i++)
		{
			GO_INSTANCE_STATE_T* pInstance = m_vectorInstances[i];
			if(pInstance->instance_id==instance_id)
			{
				return pInstance;
			}
		}
		return NULL;
	}

	GO_INSTANCE_STATE_T* CWeiQiClient::UpdateInstance(GO_INSTANCE_STATE_T* pInstance)
	{
		GO_INSTANCE_STATE_T* pOldInstance = GetGoInstance(pInstance->instance_id);
		if(pOldInstance!=NULL)
		{
			memcpy(pOldInstance,pInstance,sizeof(GO_INSTANCE_STATE_T));
			return pOldInstance;
		}else
		{
			GO_INSTANCE_STATE_T* pNew = (GO_INSTANCE_STATE_T*)EG_MALLOC(sizeof(GO_INSTANCE_STATE_T));
			memcpy(pNew,pInstance,sizeof(GO_INSTANCE_STATE_T));
			m_vectorInstances.push_back(pNew);
			return pNew;
		}
		return NULL;
	}
	void CWeiQiClient::ClearInstances()
	{

		for(int i=0;i<m_vectorInstances.size();i++)
		{
			EG_FREE(m_vectorInstances[i]);
		}
		m_vectorInstances.clear();

	}
	void CWeiQiClient::RemoveInstance(unsigned int instance_id)
	{
		int idx=-1;
		
		std::vector<GO_INSTANCE_STATE_T*>::iterator iter;
		for ( iter = m_vectorInstances.begin(); iter != m_vectorInstances.end();  ++iter )
		{

			GO_INSTANCE_STATE_T* pIns = *iter;
			if(pIns->instance_id==instance_id)
			{
				EG_FREE(pIns);
				m_vectorInstances.erase(iter);
				break;
			}

		}
	}
	BOOL CWeiQiClient::RefreshInstances(GO_INSTANCE_STATE_T* pInstance, int num)
	{
		m_numGoInstances=num;
		for(int i=0;i<m_vectorInstances.size();i++)
		{
			EG_FREE(m_vectorInstances[i]);
		}
		m_vectorInstances.clear();
		for(int i=0;i<num;i++)
		{
			m_vectorInstances.push_back((pInstance+i));

		}
		return TRUE;
	}
	unsigned int CWeiQiClient::GetNumInstances()
	{
		return m_vectorInstances.size();

	}
	GO_PLAYER_STATE_T* CWeiQiClient::UpdatePlayerState(GO_PLAYER_STATE_T* pPlayer)
	{
		GO_PLAYER_STATE_T* pOld = GetPlayerState(pPlayer->palyer_id);
		if(pOld==NULL)
		{
			GO_PLAYER_STATE_T* pNew = (GO_PLAYER_STATE_T*)EG_MALLOC(sizeof(GO_PLAYER_STATE_T));
			memcpy(pNew,pPlayer,sizeof(GO_PLAYER_STATE_T));
			m_vectorPlayerStates.push_back(pNew);
			return pNew;
		}
		else
		{
			memcpy(pOld,pPlayer,sizeof(GO_PLAYER_STATE_T));
			return pOld;
		}
		
	}
	CWeiQiClient::CWeiQiClient(){
		
		memset(m_playerName,0,MAX_PLAYER_NAME);
		strcpy(m_playerName,"NoName");
		m_chessSide=WEIQI_SIDE_BLACK;
		m_gameSize=19;
	
		m_numGoInstances=0;
	};
	CWeiQiClient::~CWeiQiClient(){
	
		int sz=m_vectorPlayerStates.size();
		for(int i=0;i<sz;i++)
		{
			GO_PLAYER_STATE_T* pPlayer = m_vectorPlayerStates[i];
			if(pPlayer!=NULL)
			{
				delete pPlayer;
			}

		}

		 sz=m_vectorInstances.size();
		for(int i=0;i<sz;i++)
		{
			GO_INSTANCE_STATE_T* pPlayer = m_vectorInstances[i];
			if(pPlayer!=NULL)
			{
				delete pPlayer;
			}

		}
	};


	void CWeiQiClient::DefineStateMachine()
	{
		static MSG_HANDLER_TBL_DEF Def_STATE_ANY_Table[]={
			{WEIQI_EVENT_LIST_GAME_RSP,HandleSocketListGameRsp},
			{WEIQI_EVENT_CREATE_GAME_RSP,HandleSocketCreateGameRsp},
			{WEIQI_EVENT_JOIN_GAME_RSP,HandleSocketJoinGameRsp},	
			{WEIQI_EVENT_JOIN_GAME,HandleSocketJoinGame},
			{WEIQI_EVENT_START_GAME,HandleSocketStartGame},
			{WEIQI_EVENT_INFO_GAME_RSP,HandleSocketInfoGameRsp},	
			{WEIQI_EVENT_EXIT_GAME_RSP,HandleSocketExitGameRsp},	
			{WEIQI_EVENT_PLAYER_EXIT,HandleSocketPlayerExit},
			{WEIQI_EVENT_PLAYER_DISCONNECT,HandleSocketPlayerDisconnect},
			{WEIQI_EVENT_GAME_UPDATED,HandleSocketGameUpdated},
			{WEIQI_EVENT_SOCKET_MOVE_CHESS,HandleSocketMoveChess},
			{WEIQI_EVENT_DRAGON_DEAD,HandleSocketDragonDead},
			{WEIQI_EVENT_NEXT_TURN,HandleSocketNextTurn},
			{WEIQI_EVENT_DIANMU_RESULT,HandleSocketDianMuResult},
			{WEIQI_EVENT_PLAYER_PASS,HandleSocketPlayerPass},
			{0,NULL}
		};
		static STATE_MACHINE_T Def_State_Table[]={
			{APP_STATE_ANY,NULL,NULL,Def_STATE_ANY_Table},
			{0,NULL,NULL,NULL}
		};
		m_pStateTable=Def_State_Table;
	};	
	STATE_MACHINE_T* CWeiQiClient::GetStateMachineTable() 
	{
		return m_pStateTable;
	}

	void CWeiQiClient::InitListener()
	{
		GetEventListener()->pfnListener = handleUIEvent;
		GetEventListener()->pListenerData = this;
	}
	void CWeiQiClient::init()
	{
		InitListener();
		DefineStateMachine();
	}

	 BOOL CWeiQiClient::HandleSocketListGameRsp(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_LIST_GAME_RSP_T* evt = (EVENT_LIST_GAME_RSP_T*)data;
		
		wqClient->ClearInstances();

		if(evt->num_of_instance>0)
		{
			GO_INSTANCE_STATE_T* pInstancesList = (GO_INSTANCE_STATE_T*)(data+sizeof(EVENT_LIST_GAME_RSP_T));		
			for(int i=0 ; i<evt->num_of_instance;i++)
			{
				wqClient->UpdateInstance((pInstancesList+i));
			}
			//payload event
			int payload_len = sizeof(GO_INSTANCE_STATE_T)*(evt->num_of_instance);
			ModelEvent event;
			EVENT_LIST_GAME_RSP_T* evtToUi = (EVENT_LIST_GAME_RSP_T*)EG_MALLOC(sizeof(EVENT_LIST_GAME_RSP_T)+payload_len);
			BYTE* payload=((BYTE*)evtToUi)+sizeof(EVENT_LIST_GAME_RSP_T);
			memcpy(payload,pInstancesList,payload_len);
			event.evCode = WEIQI_EVENT_LIST_GAME_RSP;
			evtToUi->ev_type=WEIQI_EVENT_LIST_GAME_RSP;
			evtToUi->num_of_instance = wqClient->GetNumInstances();				
			event.dwParam=(int)evtToUi; 
			event.paramLen=sizeof(EVENT_LIST_GAME_RSP_T)+payload_len;
			wqClient->GetEventModel()->Notify(&event);
			EG_FREE(evtToUi);		
		}
		else
		{
			EVENT_LIST_GAME_RSP_T hdr;
			hdr.num_of_instance=0;
			hdr.ev_type=WEIQI_EVENT_LIST_GAME_RSP;
			wqClient->GetEventModel()->NotifyEvent(WEIQI_EVENT_LIST_GAME_RSP,(int)(&hdr),sizeof(EVENT_LIST_GAME_RSP_T));

		}
		return TRUE;
	}

	 BOOL CWeiQiClient::HandleSocketInfoGameRsp(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_INFO_GAME_RSP_T* evt = (EVENT_INFO_GAME_RSP_T*)data;

		ModelEvent event;
		LOCAL_EVENT_INFO_GAME_RSP_T* evtToUi = (LOCAL_EVENT_INFO_GAME_RSP_T*)EG_MALLOC(sizeof(LOCAL_EVENT_INFO_GAME_RSP_T));
		evtToUi->instance_id=evt->instance_id;
		if(evt->bNoExist!=TRUE)
		
		{
			if(evt->instance_id!=0)
			{
				if(evt->blacker.palyer_id!=0)
				{
					evtToUi->blacker=wqClient->UpdatePlayerState(&(evt->blacker));
				}else
				{
					evtToUi->blacker=NULL;

				}
				if(evt->whiter.palyer_id!=0)
				{
					evtToUi->whiter = wqClient->UpdatePlayerState(&(evt->whiter));
				}else
				{
					evtToUi->whiter=NULL;
				}
				evtToUi->instance_state = wqClient->UpdateInstance(&(evt->instance_state ));
				evtToUi->instance_id=evt->instance_id;
				
			}
		}

		evtToUi->bNoExist=evt->bNoExist;		
		event.evCode = WEIQI_EVENT_INFO_GAME_RSP;			
		
		evtToUi->ev_type=WEIQI_EVENT_INFO_GAME_RSP;		
		event.dwParam=(int)evtToUi; 
		event.paramLen=sizeof(LOCAL_EVENT_INFO_GAME_RSP_T);
		wqClient->GetEventModel()->Notify(&event);
		EG_FREE(evtToUi);

		if(evt->bNoExist==TRUE)
		{
			wqClient->RemoveInstance(evt->instance_id);
			
		}
		
		return TRUE;
	}

	 BOOL CWeiQiClient::HandleSocketCreateGameRsp(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_CREATE_GAME_RSP_T* evt = (EVENT_CREATE_GAME_RSP_T*)data;
		wqClient->m_chessSide=evt->chess_side;
		wqClient->m_nInstanceId=evt->instance_id ;
		wqClient->m_gameSize=evt->game_size;
		wqClient->m_playerId=evt->player_id;
		
		

		ModelEvent event;
		EVENT_CREATE_GAME_RSP_T* evtToUi = (EVENT_CREATE_GAME_RSP_T*)EG_MALLOC(sizeof(EVENT_CREATE_GAME_RSP_T));
		event.evCode = WEIQI_EVENT_CREATE_GAME_RSP;
		memcpy(evtToUi,evt,sizeof(EVENT_CREATE_GAME_RSP_T));			
		event.dwParam=(int)evtToUi; 
		event.paramLen=sizeof(EVENT_CREATE_GAME_RSP_T);
		wqClient->GetEventModel()->Notify(&event);
		EG_FREE(evtToUi);
		
		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketJoinGame(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_JOIN_GAME_T* evt = (EVENT_JOIN_GAME_T*)data;



		ModelEvent event;
		event.evCode = WEIQI_EVENT_JOIN_GAME;
		event.dwParam=(int)evt; 
		event.paramLen=sizeof(EVENT_JOIN_GAME_T);
		wqClient->GetEventModel()->Notify(&event);
		
		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketStartGame(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_START_GAME_T* evt = (EVENT_START_GAME_T*)data;



		ModelEvent event;
		event.evCode = WEIQI_EVENT_START_GAME;
		event.dwParam=(int)evt; 
		event.paramLen=sizeof(EVENT_START_GAME_T);
		wqClient->GetEventModel()->Notify(&event);
	
		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketJoinGameRsp(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_JOIN_GAME_RSP_T* evt = (EVENT_JOIN_GAME_RSP_T*)data;

		if(evt->bAccept==TRUE)
		{

		}

		ModelEvent event;
		
		event.evCode = WEIQI_EVENT_JOIN_GAME_RSP;					
		event.dwParam=(int)evt; 
		event.paramLen=sizeof(EVENT_JOIN_GAME_RSP_T);
		wqClient->GetEventModel()->Notify(&event);
		
		
		return TRUE;
	}

	 BOOL CWeiQiClient::HandleSocketExitGameRsp(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_EXIT_GAME_RSP_T* evt = (EVENT_EXIT_GAME_RSP_T*)data;
	

		ModelEvent event;
		event.evCode = WEIQI_EVENT_EXIT_GAME_RSP;
		event.dwParam=(int)evt; 
		event.paramLen=sizeof(EVENT_EXIT_GAME_RSP_T);
		wqClient->GetEventModel()->Notify(&event);		
		
		return TRUE;
	}

	 BOOL CWeiQiClient::HandleSocketPlayerExit(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_PLAYER_EXIT_T* evt = (EVENT_PLAYER_EXIT_T*)data;
	

		ModelEvent event;
	
		event.evCode = WEIQI_EVENT_PLAYER_EXIT;

		event.dwParam=(int)evt; 
		event.paramLen=sizeof(EVENT_PLAYER_EXIT_T);
		wqClient->GetEventModel()->Notify(&event);		
		
		return TRUE;
	}

	 BOOL CWeiQiClient::HandleSocketPlayerDisconnect(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_PLAYER_DISCONNECT_T* evt = (EVENT_PLAYER_DISCONNECT_T*)data;
		ModelEvent event;
		event.evCode = WEIQI_EVENT_PLAYER_DISCONNECT;
		event.dwParam=(int)evt; 
		event.paramLen=sizeof(EVENT_PLAYER_DISCONNECT_T);
		wqClient->GetEventModel()->Notify(&event);		
		
		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketGameUpdated(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_GAME_UPDATED_T* evt = (EVENT_GAME_UPDATED_T*)data;
		wqClient->GetEventModel()->NotifyEvent(WEIQI_EVENT_GAME_UPDATED,(int)(evt)	,sizeof(EVENT_GAME_UPDATED_T));
		
		return TRUE;
	}

		 BOOL CWeiQiClient::HandleSocketPlayerPass(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		
		wqClient->GetEventModel()->NotifyEvent(WEIQI_EVENT_PLAYER_PASS,(int)(data)	,sizeof(EVENT_PLAYER_PASS_T));
		
		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketDianMuResult(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		
		wqClient->GetEventModel()->NotifyEvent(WEIQI_EVENT_DIANMU_RESULT,(int)(data)	,sizeof(EVENT_DIANMU_RESULT_T));
		
		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketMoveChess(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_MOVE_CHESS_T* evt = (EVENT_MOVE_CHESS_T*)data;
		
		wqClient->GetEventModel()->NotifyEvent(WEIQI_EVENT_SOCKET_MOVE_CHESS,(int)(evt)	,sizeof(EVENT_MOVE_CHESS_T));

		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketNextTurn(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);		
		wqClient->GetEventModel()->NotifyEvent(WEIQI_EVENT_NEXT_TURN,(int)(data)	,sizeof(EVENT_NEXT_TURN_T));

		return TRUE;
	}
	 BOOL CWeiQiClient::HandleSocketDragonDead(CSocketStateMachine* me,winSocketEx* client,CMsg *pMsg)
	{
		BYTE* data = NULL;
		int msg_len = pMsg->GetMessageData(data);
		CWeiQiClient* wqClient = ((CWeiQiClient*)me);
		EVENT_DRAGON_DEAD_T* evt = (EVENT_DRAGON_DEAD_T*)data;
		
		wqClient->GetEventModel()->NotifyEvent(WEIQI_EVENT_DRAGON_DEAD,(int)(evt),sizeof(EVENT_DRAGON_DEAD_T));

		return TRUE;
	}


	void CWeiQiClient::CreateGame(char* name,WEIQI_SIDE_T side,int game_size)
	{
		EVENT_CREATE_GAME_T msg;
		memcpy(this->m_playerName,name,MAX_PLAYER_NAME);
		m_chessSide=side;
		m_gameSize=game_size;
		msg.chess_side=m_chessSide;
		msg.ev_type=WEIQI_EVENT_CREATE_GAME;
		msg.game_size = m_gameSize;
		memcpy(msg.name,name,MAX_PLAYER_NAME);
		SendMsgToServer(WEIQI_EVENT_CREATE_GAME,(BYTE*)(&msg),sizeof(EVENT_CREATE_GAME_T));
	}

	void CWeiQiClient::ListGame(char* name)
	{
		EVENT_LIST_GAME_T msg;
		memcpy(this->m_playerName,name,MAX_PLAYER_NAME);
		msg.ev_type=WEIQI_EVENT_LIST_GAME;
		memset(msg.name,0,MAX_PLAYER_NAME);
		memcpy(msg.name,name,MAX_PLAYER_NAME);
		SendMsgToServer(WEIQI_EVENT_LIST_GAME,(BYTE*)(&msg),sizeof(EVENT_LIST_GAME_T));
	}
	void CWeiQiClient::InfoGame(unsigned int instance_id)
	{
		EVENT_INFO_GAME_T msg;
		msg.ev_type=WEIQI_EVENT_INFO_GAME;
		msg.instance_id=instance_id;
		SendMsgToServer(WEIQI_EVENT_INFO_GAME,(BYTE*)(&msg),sizeof(EVENT_INFO_GAME_T));
	}
	void CWeiQiClient::HandleUIMoveChess(EVENT_MOVE_CHESS_T* evt)
	{
		EVENT_MOVE_CHESS_T* data = (EVENT_MOVE_CHESS_T*)EG_MALLOC(sizeof(EVENT_MOVE_CHESS_T));

		memcpy(data,evt,sizeof(EVENT_MOVE_CHESS_T));
	
		data->ev_type=WEIQI_EVENT_UI_MOVE_CHESS;
	
		SendMsgToServer(data->ev_type,(BYTE*)data,sizeof(EVENT_MOVE_CHESS_T));
		EG_FREE(data);
	}
	void CWeiQiClient::HandleUIPlayerPass(EVENT_PLAYER_PASS_T* evt)
	{

	
		SendMsgToServer(WEIQI_EVENT_PLAYER_PASS,(BYTE*)evt,sizeof(EVENT_PLAYER_PASS_T));

	}
	void CWeiQiClient::HandleUICreateGame(char* name,WEIQI_SIDE_T side,int game_size)
	{
		CreateGame(name,side,game_size);
	}
	void CWeiQiClient::HandleUIReqDianMu(EVENT_REQ_DIANMU_T* evt)
	{
		SendMsgToServer(WEIQI_EVENT_REQ_DIANMU,(BYTE*)evt,sizeof(EVENT_REQ_DIANMU_T));
	}

	void CWeiQiClient::JoinGame(char* name,WEIQI_SIDE_T side,unsigned int instance_id)
	{
		EVENT_JOIN_GAME_T msg;
		memcpy(this->m_playerName,name,MAX_PLAYER_NAME);
	
		msg.src_chess_side =side;
		msg.instance_id=instance_id;		
		msg.ev_type=WEIQI_EVENT_JOIN_GAME;
		memcpy(msg.src_name,name,MAX_PLAYER_NAME);
		SendMsgToServer(WEIQI_EVENT_JOIN_GAME,(BYTE*)(&msg),sizeof(EVENT_JOIN_GAME_T));

	}
	void CWeiQiClient::JoinGameRsp(EVENT_JOIN_GAME_RSP_T* evt)
	{
		EVENT_JOIN_GAME_RSP_T msg;
		memcpy(&msg,evt,sizeof(EVENT_JOIN_GAME_RSP_T));
		SendMsgToServer(WEIQI_EVENT_JOIN_GAME_RSP,(BYTE*)(&msg),sizeof(EVENT_JOIN_GAME_RSP_T));

	}
	void CWeiQiClient::ExitGame(EVENT_EXIT_GAME_T* evt)
	{
		EVENT_EXIT_GAME_T msg;
		memcpy(&msg,evt,sizeof(EVENT_EXIT_GAME_T));
		SendMsgToServer(WEIQI_EVENT_EXIT_GAME,(BYTE*)(&msg),sizeof(EVENT_EXIT_GAME_T));

	}
	 void CWeiQiClient::handleUIEvent(void *pUserData, ModelEvent *pEvent)
	{
		unsigned int evCode = pEvent->evCode;
		switch (evCode)
		{

		case WEIQI_EVENT_CREATE_GAME:
			{
				EVENT_CREATE_GAME_T* data = (EVENT_CREATE_GAME_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->HandleUICreateGame((char*)(data->name),data->chess_side,data->game_size );	
				break;
			}
		case WEIQI_EVENT_JOIN_GAME:
			{
				EVENT_JOIN_GAME_T* data = (EVENT_JOIN_GAME_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->JoinGame((char*)(data->src_name),data->src_chess_side,data->instance_id);
				break;
			}
		case WEIQI_EVENT_JOIN_GAME_RSP:
			{
				EVENT_JOIN_GAME_RSP_T* data = (EVENT_JOIN_GAME_RSP_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->JoinGameRsp(data);
				break;
			}
		case WEIQI_EVENT_LIST_GAME:
			{
				EVENT_LIST_GAME_T* data = (EVENT_LIST_GAME_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->ListGame((char*)(data->name));
				break;
			}
		case WEIQI_EVENT_INFO_GAME:
			{
				EVENT_INFO_GAME_T* data = (EVENT_INFO_GAME_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->InfoGame(data->instance_id);
				break;
			}
		case WEIQI_EVENT_EXIT_GAME:
			{
				EVENT_EXIT_GAME_T* data = (EVENT_EXIT_GAME_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->ExitGame(data);
				break;
			}
		case WEIQI_EVENT_UI_MOVE_CHESS:
			{
				EVENT_MOVE_CHESS_T* data = (EVENT_MOVE_CHESS_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->HandleUIMoveChess(data);
				break;
			}
		case WEIQI_EVENT_REQ_DIANMU:
			{
				EVENT_REQ_DIANMU_T* data = (EVENT_REQ_DIANMU_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->HandleUIReqDianMu(data);
				break;
			}
		case WEIQI_EVENT_UI_PLAYER_PASS:
			{
				EVENT_PLAYER_PASS_T* data = (EVENT_PLAYER_PASS_T*)(pEvent->dwParam);
				CWeiQiClient* me = (CWeiQiClient*)pUserData;
				me->HandleUIPlayerPass(data);
				break;
			}

		}
		
	};
	void CWeiQiClient::HelloServer(char* name)
	{		
			EVENT_HELLO_T evt;
			memcpy(evt.name,(char*)name,MAX_PLAYER_NAME);

			this->SendMsgToServer(WEIQI_EVENT_HELLO,(BYTE*)(&evt),sizeof(EVENT_HELLO_T));
	}
